package cn.gson.crm.model.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.gson.crm.model.Jdbc;
import cn.gson.crm.model.entity.ClassEntity;

public class ClassDao {

	/**
	 * 获取所有的班级数
	 * 
	 * @return
	 * @throws SQLException
	 */
	public List<ClassEntity> getClassAll() throws SQLException {
		String sql = "SELECT * FROM class ";
		List<Map<String, Object>> data = Jdbc.getInstace().executeQueryForList(sql);
		List<ClassEntity> classEntities = new ArrayList<>();
		ClassEntity classEntity = null;
		for (Map<String, Object> map : data) {
			classEntity = builderClass(map);
			classEntities.add(classEntity);
		}
		return classEntities;

	}

	private ClassEntity builderClass(Map<String, Object> map) {
		ClassEntity classEntity = new ClassEntity();
		classEntity.setClassid((Integer) map.get("class_id"));
		classEntity.setClassname((String) map.get("class_name"));
		classEntity.setClassmonitor((String) map.get("class_monitor"));
		classEntity.setClassteacher((String) map.get("class_teacher"));
		return classEntity;
	}
}
